package com.niit.session23;
//创建线程的方式2：实现Runnable接口
public class RunnableDemo implements Runnable{

	@Override
	public void run() {
//		获取当前线程的名字
		System.out.println(Thread.currentThread().getName());
//		获取当前线程的优先级
		System.out.println("子线程的优先级："+Thread.currentThread().getPriority());
		for (int i = 1; i <= 100; i++) {
			System.out.println("子线程-->"+i);
		}		
	}
	
	public static void main(String[] args) {
		RunnableDemo runnableDemo = new RunnableDemo();
//		由于Runnable接口没有start方法，所以要启动线程需要借助Thread类
		Thread thread = new Thread(runnableDemo);
		thread.start();
//		设置线程的优先级，数字从1到10，数字越大优先级越高
		Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
		System.out.println(Thread.currentThread().getName());
		System.out.println("主线程的优先级："+Thread.currentThread().getPriority());
		
		for (int i = 1; i <= 100; i++) {
			System.out.println("主线程==》"+i);
		}
	}

	

}
